
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/statics/layui/layui.js" charset="UTF-8"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/statics/layui/css/layui.css"/>
</head>

<style>
    #form{
        border-radius: 10px;
        padding-left: 20px;
    }
</style>
<body>
<br><br>
<div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">真实姓名：</label>
                <div class="layui-input-block">
                    <input class="layui-input" name="realName" id="realName" autocomplete="off">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">角色：</label>
                <div class="layui-input-block">
                    <select name="roleId" lay-filter="aihao">
                        <option value=""></option>
                        <option value="1">管理系统员</option>
                        <option value="2">店长</option>
                        <option value="3">店员</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" onclick="history.back()">返回</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-warm" lay-event="add">新增</button>
    </div>
</script>
<table class="layui-hide" id="test"  lay-filter="test"></table>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="view">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<div id="view">
    <p id="p1"></p>
    <p id="p2"></p>
    <p id="p3"></p>
    <p id="p4"></p>
    <p id="p5"></p>
    <p id="p6"></p>
    <p id="p7"></p>
</div>

<script>
    layui.use(['table','form','jquery'], function(){
        var table = layui.table;
        var form=layui.form;
        var $=layui.jquery;

        var tableIns=table.render({
            elem: '#test'
            ,url:'${pageContext.request.contextPath}/sysUser/list'
            ,toolbar:'#toolbarDemo'
            ,cols: [[
                {field:'id', width:100, title: '编号'}
                ,{field:'account', width:100, title: '账号'}
                ,{field:'realName', width:120, title: '真实姓名'}
                ,{field:'roleId', width:100, title: '角色'}
                ,{field:'sex', title: '性别', width: 80}
                ,{field:'age', width:80, title: '年龄'}
                ,{field:'phone', width:150, title: '电话'}
                ,{fixed: 'right', title:'操作', minWidth: 125, toolbar: '#barDemo'}
            ]]
            ,page: true
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            console.log(data.field)
            //这里以搜索为例
            tableIns.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    realName: data.field.realName
                    ,roleId: data.field.roleId
                    //…
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });

        <%--//工具栏事件--%>
        <%--table.on("toolbar(text)",function (data) {--%>
        <%--    alert(data);--%>
        <%--    var id=data.file.id;--%>
        <%--    switch (data.event) {--%>
        <%--        case "add":--%>
        <%--            window.open('${pageContext.request.contextPath}/sysUser/toUserAdd');--%>
        <%--            break;--%>
        <%--    }--%>
        <%--})--%>

        // 工具栏事件
        table.on('toolbar(test)', function(obj){
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var othis = lay(this);
            switch(obj.event){
                case 'add':
                    location.href="toUserAdd";
                    break;
            };
        });

        //触发单元格工具事件
        table.on('tool(test)', function(obj){ // 双击 toolDouble
            var data = obj.data;
            //console.log(obj)a
            // if(obj.event === 'view1'){
            //     window.open("view/"+data.id);
            // }else
            if(obj.event === 'view'){
                layer.open({
                    type:2,
                    title:"",
                    area:["80%", "80%"],
                    content:["${pageContext.request.contextPath}/sysUser/view2/"+data.id]
                })
                <%--location.href="${pageContext.request.contextPath}/sysUser/view2/"+data.id;--%>
                // $.get("view/"+data.id,function (data) {
                    // $("#p1").text("账号："+data.account);
                    // $("#p2").text("真实姓名："+data.realName);
                    // if (data.sex=="1"){
                    //     $("#p3").text("性别：女");
                    // }else {
                    //     $("#p3").text("性别：男");
                    // }
                    // $("#p4").text("出生日期："+data.birthday);
                    // $("#p5").text("电话："+data.phone);
                    // $("#p6").text("地址："+data.address);
                    // var roleId;
                    // if (data.roleId==1){
                    //     roleId="系统管理员"
                    // }else if(data.roleId==2){
                    //     roleId="店长"
                    // }else if(data.roleId==3){
                    //     roleId="店员"
                    // }
                    // $("#p7").text("角色："+roleId);
                    <%--$("#p8").attr({"src":"${pageContext.request.contextPath}/statics/upload/"+data.idpicpath,"width":"100px","height":"120px","value":"证件照："});--%>
                // },"json")
            }else if(obj.event === 'del'){
                layer.confirm("真的删除行吗",function (index){
                    $.get('${pageContext.request.contextPath}/sysUser/delete/'+data.id,function (data) {
                        layer.close(index);
                        if (data==='1'){
                            location.reload();
                        }else {
                            alert("删除失败");
                        }
                    })
                })
            }
            else if(obj.event==='edit'){
                <%--layer.open({--%>
                <%--    type:2,--%>
                <%--    title:"",--%>
                <%--    area:["80%", "80%"],--%>
                <%--    content:["${pageContext.request.contextPath}/sysUser/toEdit/id="+data.id]--%>
                <%--})--%>
                location.href="${pageContext.request.contextPath}/sysUser/toEdit/"+data.id;
            }
        });
    });


</script>
</body>
</html>